-
Notifications
You must be signed in to change notification settings - Fork 140
Support for Terraform Search (.tfquery.hcl) files #2007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 21a998a.
ea24c6b
to
e87b916
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
@@ -46,7 +47,7 @@ This allows IntelliSense to remain accurate e.g. when switching branches in VCS | |||
or when there are any other changes made to these files outside the editor. | |||
|
|||
If the client implements file watcher, it should watch for any changes | |||
in `**/*.tf`, `**/*.tfvars`, `*.tfstack.hcl`, `**/*.tfstack.hcl` and `**/*.tfstack.hcl` files in the workspace. | |||
in `**/*.tf`, `**/*.tfvars`, `**.tfstack.hcl`, `**/*.tfcomponent.hcl`, `**/*.tfdeploy.hcl` and `**/*.tfquery.hcl` files in the workspace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in `**/*.tf`, `**/*.tfvars`, `**.tfstack.hcl`, `**/*.tfcomponent.hcl`, `**/*.tfdeploy.hcl` and `**/*.tfquery.hcl` files in the workspace. | |
in `**/*.tf`, `**/*.tfvars`, `**/*.tfstack.hcl`, `**/*.tfcomponent.hcl`, `**/*.tfdeploy.hcl` and `**/*.tfquery.hcl` files in the workspace. |
_, err := f.stateStore.JobStore.EnqueueJob(ctx, job.Job{ | ||
Dir: dir, | ||
Func: func(ctx context.Context) error { | ||
return jobs.SchemaSearchValidation(ctx, f.store, f.moduleFeature, f.rootFeature, dir.Path()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you did not implement ReferenceValidation?
f.logger.Printf("loading module metadata returned error: %s", jobErr) | ||
} | ||
|
||
// Reference collection jobs will depend on this one, so we move it here in advance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In stacks and modules we have a decode block here that resolves component or module calls, so you get autocompletion for those. Is there not something similiar for tfquery files?
} | ||
|
||
func searchPathContext(record *state.SearchRecord, stateReader CombinedReader) (*decoder.PathContext, error) { | ||
resolvedVersion := tfschema.ResolveVersion(stateReader.TerraformVersion(record.Path()), record.Meta.CoreRequirements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to have a job to parse terraform version in search for this to work? Or does this pull this from moduleReader?
// ParseSearchConfiguration parses the whole Search configuration, | ||
// i.e. turns bytes of `*.tfquery.hcl` files into AST ([*hcl.File]). | ||
func ParseSearchConfiguration(ctx context.Context, fs ReadOnlyFS, searchStore *state.SearchStore, searchPath string) error { | ||
record, err := searchStore.SearchRecordByPath(searchPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of SearchRecordByPath makes me wonder if this should have all been Query
, but I guess it's one use case so it being confusing (sounding like "search all records by path" instead of "get SearchRecords by path")
isMatchingLanguageId := (rpcContext.LanguageID == lsp.Search.String()) | ||
|
||
// Only parse the file that's being changed/opened, unless this is 1st-time parsing | ||
if record.DiagnosticsState[globalAst.HCLParsingSource] == operation.OpStateLoaded && | ||
rpcContext.IsDidChangeRequest() && | ||
isMatchingLanguageId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isMatchingLanguageId := (rpcContext.LanguageID == lsp.Search.String()) | |
// Only parse the file that's being changed/opened, unless this is 1st-time parsing | |
if record.DiagnosticsState[globalAst.HCLParsingSource] == operation.OpStateLoaded && | |
rpcContext.IsDidChangeRequest() && | |
isMatchingLanguageId { | |
// Only parse the file that's being changed/opened, unless this is 1st-time parsing | |
if record.DiagnosticsState[globalAst.HCLParsingSource] == operation.OpStateLoaded && | |
rpcContext.IsDidChangeRequest() && | |
rpcContext.LanguageID == lsp.Search.String() { |
This was only done because stacks has multiple files. I don't think Search has more than one?
targets := make(reference.Targets, 0) | ||
targets = append(targets, searchTargets...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there "built-in" references to consider like Stacks has?
Description
This provides completion, hover, and diagnostics for Terraform Search files. Adds new language id - terraform-search.
Related PRs:
Demo
Note
Around 2000 lines of code are related to test cases
TODO